
// Copyright (C) 2007 Richard Uhler
// This file is part of Esiply.
//
// Esiply is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License, Version 2,
// as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include "Completion.h"
#include "EsniFunction.h"

EsniFunction::EsniFunction(Scope* scope, esni_function_t function,
        const char* params)
    : NormalFunction(scope, params), m_function(function)
{}

Value* EsniFunction::evaluate(Scope* scope)
{
    Value* res = ((Value*)(*m_function)(scope))->getValue();

    // If res is a completion, just return it,
    // otherwise wrap it in the completion (return, value, empty)
    if (res->getType() == VT_COMPLETION)
    {
        return res;
    }
    return new Completion(CT_RETURN, res, Completion::empty);
}

